﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LDTB.Service;

namespace LDTB
{
    public partial class LoginFrm : Form
    {
        LDTBDataDataContext ds = DataService.DB;
        public User user;

        public LoginFrm()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ConfigForm cf = new ConfigForm();
            cf.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string username = this.txtUserName.Text;
            string pwd = this.txtPwd.Text;

            var us = (from u in ds.Users
                      where u.UserName == username && u.PassWord == pwd
                      select u).FirstOrDefault();

            if (us != null)
            {
                this.Visible = false;
                this.user = us;
                new FormMain(this).Show();

            }
            else
            {

                MessageBox.Show("Kiểm tra tên đăng nhập hoặc mật khẩu");

            }

        }


        private void LoginFrm_Shown(object sender, EventArgs e)
        {
            this.txtUserName.Focus();
        }
    }
}
